1 using UnityEngine;
2 using
System.Collections;
3
4
5 ///
<summary>
6 ///
tweens scale along a path at constant speed between nodes. isRelative makes the path scale
7 ///
relative to the start scale of the object. a "from" tween will reverse the path and make the start
8 ///
scale be the last node in the path.
9 ///
</summary>
10 public
class ScalePathTweenProperty : AbstractTweenProperty
11 {
12     
protected Transform _target;
13     
protected Vector3 _startValue;
14     
15     
private GoSpline _path;
16     
17     
18     
public ScalePathTweenProperty( GoSpline path, bool isRelative = false ) : base( isRelative )
19     {
20         _path = path;
21     }
22     
23     
24     
#region Object overrides
25     
26     
public override int GetHashCode()
27     {
28         
return base.GetHashCode();
29     }
30     
31     
32     
public override bool Equals( object obj )
33     {
34         
// if base already determined that we are equal no need to check further
35         
if( base.Equals( obj ) )
36             
return true;
37         
38         
// we can be equal if the other object is a ScaleTweenProperty
39         
return obj.GetType() == typeof( ScaleTweenProperty );
40     }
41     
42     
#endregion
43     
44     
45     
public override void prepareForUse()
46     {
47         _target = _ownerTween.target
as Transform;
48         
49         
// if this is a from tween first reverse the path then build it
50         
if( _ownerTween.isFrom )
51             _path.reverseNodes();
52         
else
53             _path.unreverseNodes();
54         
55         _path.buildPath();
56         
57         
// a from tween means the start value is the last node
58         
if( _ownerTween.isFrom )
59             _startValue = _path.getLastNode();
60         
else
61             _startValue = _target.localScale;
62     }
63     
64
65     
public override void tick( float totalElapsedTime )
66     {
67         
var easedTime = _easeFunction( totalElapsedTime, 0, 1, _ownerTween.duration );
68         
var vec = _path.getPointOnPath( easedTime );
69         
70         
// if we are relative, add the vec to our startValue
71         
if( _isRelative )
72             vec += _startValue;
73     
74         _target.localScale = vec;
75     }
76
77 }



Trò chơi Angry Birds trong UNITY Engine 31.704 lượt xem

Gõ tìm kiếm nhanh...